include ../etc/Makefile.conf

OCAML_MLS := int64.ml char.ml string.ml set.ml complex.ml		\
listLabels.ml sort.ml int32.ml stringLabels.ml arrayLabels.ml sys.ml	\
hashtbl.ml marshal.ml obj.ml stream.ml genlex.ml lexing.ml map.ml	\
moreLabels.ml queue.ml stack.ml stdLabels.ml weak.ml camlinternalOO.ml	\
oo.ml buffer.ml format.ml callback.ml nativeint.ml printf.ml		\
parsing.ml arg.ml digest.ml filename.ml gc.ml printexc.ml random.ml	\
scanf.ml

STD_MLS := $(addprefix lazy_, $(OCAML_MLS))
STD_MLIS := $(STD_MLS:.ml=.mli)
NEW_MLS := lazy_list.ml lazy_array.ml lazy_lazy.ml lazy_pervasives.ml
NEW_MLIS := $(LAZY_MLS:.ml=.mli)
MLS := $(NEW_MLS) $(STD_MLS)
MLIS := $(MLS:.ml=.mli)
CMIS := $(MLS:.ml=.cmi)
CMOS := $(MLS:.ml=.cmo)
CMXS := $(MLS:.ml=.cmx)

ARCHS := lazy-ocaml.cma lazy-ocaml.cmxa

FLAGS := -w Ae -warn-error A -c

all: $(MLS) $(MLIS) $(CMIS) $(CMOS) $(CMXS) $(ARCHS)

lazy-ocaml.cma: $(CMOS)
	ocamlc -a $(CMOS) -o $@

lazy-ocaml.cmxa: $(CMXS)
	ocamlopt -a $(CMXS) -o $@

lazy_%.ml: ocaml/%.ml $(BIN)/lazy-ocaml $(BIN)/fmteraser
	$(BIN)/lazy-ocaml $<

lazy_%.mli: ocaml/%.mli $(BIN)/lazy-ocaml $(BIN)/fmteraser
	$(BIN)/lazy-ocaml $<

%Labels.cmi: %Labels.mli
	$(OCAMLC) -nolabels $(FLAGS) $<

%Labels.cmo: %Labels.ml %Labels.cmi
	$(OCAMLC) -nolabels $(FLAGS) $<

%Labels.cmx: %Labels.ml %Labels.cmi
	$(OCAMLOPT) -nolabels $(FLAGS) $<

%.cmi: %.mli
	$(OCAMLC) $(FLAGS) $<

%.cmo: %.ml %.cmi
	$(OCAMLC) $(FLAGS) $<

%.cmx: %.ml %.cmi
	$(OCAMLOPT) $(FLAGS) $<

tests:
	@make --no-print-directory -C $(TESTS) tests

clean:
	@rm -f *.o *.a *.cmi *.cmo *.cmx *.cma *.cmxa $(STD_MLS) $(STD_MLIS)

.PHONY: all tests clean

lazy_array.cmi: lazy_list.cmi
lazy_array.cmo: lazy_list.cmi
lazy_array.cmx: lazy_list.cmi

lazy_pervasives.cmi: lazy_list.cmi
lazy_pervasives.cmo: lazy_list.cmi
lazy_pervasives.cmx: lazy_list.cmi

lazy_genlex.cmi: lazy_stream.cmi
lazy_genlex.cmo: lazy_stream.cmi
lazy_genlex.cmx: lazy_stream.cmi

lazy_moreLabels.cmi: lazy_set.cmi
lazy_moreLabels.cmo: lazy_set.cmi
lazy_moreLabels.cmx: lazy_set.cmi

lazy_printf.cmi: lazy_format.cmi
lazy_printf.cmo: lazy_format.cmi
lazy_printf.cmx: lazy_format.cmi

lazy_camlinternalOO.cmi: lazy_obj.cmi
lazy_camlinternalOO.cmo: lazy_obj.cmi
lazy_camlinternalOO.cmx: lazy_obj.cmi
